package com.wenyu.wenyuyuedu.adapter.homepagefragment;

import android.content.Context;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wenyu.wenyuyuedu.R;
import com.wenyu.wenyuyuedu.activity.homepage.InvitationDetailActivity;
import com.wenyu.wenyuyuedu.bean.homepager.Home_All_InvitationBean;
import com.wenyu.wenyuyuedu.utils.TimeFormat;
import com.wenyu.wenyuyuedu.view.CircleImageView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/2/23.
 * 首页全部--帖子详情的adapter
 */

public class InvitationDetailAdapter extends BaseAdapter {
    private List<Home_All_InvitationBean.InfoBean.ForumLzlReplyBean> forumLzlReply = new ArrayList<>();
    private Context context;
    private View view;
    private String mName;

    public InvitationDetailAdapter(InvitationDetailActivity invitationDetailActivity, String name) {
        this.mName = name;
        this.context = invitationDetailActivity;
    }


    @Override
    public int getCount() {
        return forumLzlReply.size();
    }

    @Override
    public Object getItem(int i) {
        return forumLzlReply.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        InvitationDetailHolder holder = null;
        if (view == null) {
            holder = new InvitationDetailHolder();
            view = View.inflate(context, R.layout.invitation_detail_item, null);
            holder.invitation_nickname = (TextView) view.findViewById(R.id.invitation_nickname);
            holder.invitation_releasetime = (TextView) view.findViewById(R.id.invitation_releasetime);
            //holder.item_zan_count = (TextView) view.findViewById(R.id.item_zan_count);
            //  holder.invitation_content = (TextView) view.findViewById(invitation_content);
            holder.invitation_head = (CircleImageView) view.findViewById(R.id.invitation_head);
            holder.invitation_down = (ImageView) view.findViewById(R.id.invitation_down);
            holder.tv_huifu_name = (TextView) view.findViewById(R.id.tv_huifu_name);
            view.setTag(holder);
        } else {
            holder = (InvitationDetailHolder) view.getTag();
        }
           /*被回复人的昵称*/
        String to_comment_name = forumLzlReply.get(i).getTo_comment_name();
        boolean equals = mName.equals(to_comment_name);
        if (mName.equals(to_comment_name)) {
            //   etInvitation.setHint(Html.fromHtml("<font color= '#576b95'> 评论@</font>" + nickname1 + ":"));
            String content = forumLzlReply.get(i).getContent();
            holder.tv_huifu_name.setText(Html.fromHtml("" + content));
        } else {
            String content = forumLzlReply.get(i).getContent();
            holder.tv_huifu_name.setText(Html.fromHtml("回复" + "<font color= '#576b95'>" + to_comment_name + "</font>" + ":" + content));

        }
        Glide.with(context)
                .load(forumLzlReply.get(i).getComment_icon())
                .into(holder.invitation_head);
        String ctime = forumLzlReply.get(i).getCtime();
        Long aLong = Long.valueOf(ctime);
        String dateToString = TimeFormat.getDateToString(aLong);
        holder.invitation_releasetime.setText(dateToString);
        holder.invitation_nickname.setText(forumLzlReply.get(i).getComment_name());
        return view;
    }

    class InvitationDetailHolder {
        TextView invitation_item_comment_count, invitation_nickname,
                invitation_releasetime, item_zan_count, tv_huifu_name;
        CircleImageView invitation_head;
        ImageView invitation_down;

    }

    public void updateRes(List<Home_All_InvitationBean.InfoBean.ForumLzlReplyBean> forumLzlReply) {
        if (forumLzlReply != null) {
            this.forumLzlReply.addAll(forumLzlReply);
            notifyDataSetChanged();
        }
    }
}
